package com.xiaoshuidi.cloud.module.finance.controller.admin.withdraw;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.excel.core.util.ExcelUtils;
import com.xiaoshuidi.cloud.module.finance.controller.admin.withdraw.vo.ThirdWithdrawQueryReqVO;
import com.xiaoshuidi.cloud.module.finance.controller.admin.withdraw.vo.ThirdWithdrawRespVO;
import com.xiaoshuidi.cloud.module.finance.service.withdraw.FinanceThirdWithdrawService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "第三方提现")
@RestController
@RequestMapping("/finance/third/withdraw")
@Validated
public class ThirdWithdrawController {
    @Resource
    private FinanceThirdWithdrawService financeThirdWithdrawService;

//    @PostMapping("/retry/{id}")
//    @Operation(summary = "重新发起提现")
//    public CommonResult<Boolean> retryWithdraw(@PathVariable("id") Long id) {
//        return success(financeThirdWithdrawService.retryWithdraw(id));
//    }


    @PostMapping("/list")
    @Operation(summary = "提现列表")
    public CommonResult<PageResult<ThirdWithdrawRespVO>> list(@RequestBody ThirdWithdrawQueryReqVO reqVO) {
        return success(financeThirdWithdrawService.page(reqVO));
    }

    @PostMapping("/export-list")
    @Operation(summary = "提现导出")
    public void exportList(@RequestBody ThirdWithdrawQueryReqVO reqVO, HttpServletResponse response) throws IOException {
        List<ThirdWithdrawRespVO> list = financeThirdWithdrawService.list(reqVO);
        ExcelUtils.write(response, "提现列表.xls", "提现列表", ThirdWithdrawRespVO.class, list);
    }
}
